<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LINE 1 &quot;libraries\\base\\GHC\\IO\\Handle\\Lock\\Windows.hsc&quot; #-}</span><span>
</span><span id="line-1"></span><span class="hs-pragma">{-# LANGUAGE CPP #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE InterruptibleFFI #-}</span><span>
</span><span id="line-3"></span><span class="hs-pragma">{-# LANGUAGE LambdaCase #-}</span><span>
</span><span id="line-4"></span><span class="hs-pragma">{-# LANGUAGE MultiWayIf #-}</span><span>
</span><span id="line-5"></span><span class="hs-pragma">{-# LANGUAGE NoImplicitPrelude #-}</span><span>
</span><span id="line-6"></span><span>
</span><span id="line-7"></span><span class="hs-comment">-- | File locking for Windows.</span><span>
</span><span id="line-8"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">GHC.IO.Handle.Lock.Windows</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-9"></span><span>
</span><span id="line-10"></span><span>
</span><span id="line-11"></span><span>
</span><span id="line-12"></span><span>
</span><span id="line-13"></span><span class="hs-pragma">{-# LINE 15 &quot;libraries\\base\\GHC\\IO\\Handle\\Lock\\Windows.hsc&quot; #-}</span><span class="hs-cpp">

#include &lt;windows_cconv.h&gt;
</span><span>
</span><span id="line-18"></span><span>
</span><span id="line-19"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Data.Bits</span><span>
</span><span id="line-20"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Data.Function</span><span>
</span><span id="line-21"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">GHC.IO.Handle.Windows</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">handleToHANDLE</span><span class="hs-special">)</span><span>
</span><span id="line-22"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Foreign.C.Error</span><span>
</span><span id="line-23"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Foreign.C.Types</span><span>
</span><span id="line-24"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Foreign.Marshal.Alloc</span><span>
</span><span id="line-25"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Foreign.Marshal.Utils</span><span>
</span><span id="line-26"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">GHC.Base</span><span>
</span><span id="line-27"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="hs-identifier">GHC.Event.Windows</span><span> </span><span class="hs-keyword">as</span><span> </span><span class="hs-identifier">Mgr</span><span>
</span><span id="line-28"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">GHC.Event.Windows</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">LPOVERLAPPED</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">withOverlapped</span><span class="hs-special">)</span><span>
</span><span id="line-29"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">GHC.IO.FD</span><span>
</span><span id="line-30"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">GHC.IO.Handle.FD</span><span>
</span><span id="line-31"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">GHC.IO.Handle.Types</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Handle</span><span class="hs-special">)</span><span>
</span><span id="line-32"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">GHC.IO.Handle.Lock.Common</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">LockMode</span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-33"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">GHC.IO.SubSystem</span><span>
</span><span id="line-34"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">GHC.Windows</span><span>
</span><span id="line-35"></span><span>
</span><span id="line-36"></span><span class="hs-identifier">lockImpl</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Handle</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">String</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">LockMode</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Bool</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">Bool</span><span>
</span><span id="line-37"></span><span class="hs-identifier">lockImpl</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">lockImplPOSIX</span><span> </span><span class="hs-operator">&lt;!&gt;</span><span> </span><span class="hs-identifier">lockImplWinIO</span><span>
</span><span id="line-38"></span><span>
</span><span id="line-39"></span><span class="hs-identifier">lockImplWinIO</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Handle</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">String</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">LockMode</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Bool</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">Bool</span><span>
</span><span id="line-40"></span><span class="hs-identifier">lockImplWinIO</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-identifier">ctx</span><span> </span><span class="hs-identifier">mode</span><span> </span><span class="hs-identifier">block</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-41"></span><span>  </span><span class="hs-identifier">wh</span><span>      </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">handleToHANDLE</span><span> </span><span class="hs-identifier">h</span><span>
</span><span id="line-42"></span><span>  </span><span class="hs-identifier">fix</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">retry</span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-43"></span><span>          </span><span class="hs-keyword">do</span><span> </span><span class="hs-identifier">retcode</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">Mgr.withException</span><span> </span><span class="hs-identifier">ctx</span><span> </span><span class="hs-operator">$</span><span>
</span><span id="line-44"></span><span>                          </span><span class="hs-identifier">withOverlapped</span><span> </span><span class="hs-identifier">ctx</span><span> </span><span class="hs-identifier">wh</span><span> </span><span class="hs-number">0</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">startCB</span><span> </span><span class="hs-identifier">wh</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">completionCB</span><span>
</span><span id="line-45"></span><span>             </span><span class="hs-keyword">case</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-46"></span><span>              </span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">retcode</span><span> </span><span class="hs-operator">==</span><span> </span><span class="hs-number">995</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">retry</span><span>
</span><span id="line-47"></span><span class="hs-pragma">{-# LINE 47 &quot;libraries\\base\\GHC\\IO\\Handle\\Lock\\Windows.hsc&quot; #-}</span><span>
</span><span id="line-47"></span><span>                </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">retcode</span><span> </span><span class="hs-operator">==</span><span> </span><span class="hs-number">0</span><span>           </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-identifier">True</span><span>
</span><span id="line-48"></span><span class="hs-pragma">{-# LINE 48 &quot;libraries\\base\\GHC\\IO\\Handle\\Lock\\Windows.hsc&quot; #-}</span><span>
</span><span id="line-48"></span><span>                </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">retcode</span><span> </span><span class="hs-operator">==</span><span> </span><span class="hs-number">33</span><span> </span><span class="hs-operator">&amp;&amp;</span><span> </span><span class="hs-identifier">not</span><span> </span><span class="hs-identifier">block</span><span>
</span><span id="line-49"></span><span class="hs-pragma">{-# LINE 49 &quot;libraries\\base\\GHC\\IO\\Handle\\Lock\\Windows.hsc&quot; #-}</span><span>
</span><span id="line-49"></span><span>                    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-identifier">False</span><span>
</span><span id="line-50"></span><span>                </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">otherwise</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">failWith</span><span> </span><span class="hs-identifier">ctx</span><span> </span><span class="hs-identifier">retcode</span><span>
</span><span id="line-51"></span><span>    </span><span class="hs-keyword">where</span><span>
</span><span id="line-52"></span><span>      </span><span class="hs-identifier">cmode</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="hs-identifier">mode</span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-53"></span><span>                </span><span class="hs-identifier">SharedLock</span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-number">0</span><span>
</span><span id="line-54"></span><span>                </span><span class="hs-identifier">ExclusiveLock</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-number">2</span><span>
</span><span id="line-55"></span><span class="hs-pragma">{-# LINE 55 &quot;libraries\\base\\GHC\\IO\\Handle\\Lock\\Windows.hsc&quot; #-}</span><span>
</span><span id="line-55"></span><span>      </span><span class="hs-identifier">flags</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="hs-identifier">block</span><span>
</span><span id="line-56"></span><span>                 </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">cmode</span><span>
</span><span id="line-57"></span><span>                 </span><span class="hs-keyword">else</span><span> </span><span class="hs-identifier">cmode</span><span> </span><span class="hs-operator">.|.</span><span> </span><span class="hs-number">1</span><span>
</span><span id="line-58"></span><span class="hs-pragma">{-# LINE 58 &quot;libraries\\base\\GHC\\IO\\Handle\\Lock\\Windows.hsc&quot; #-}</span><span>
</span><span id="line-58"></span><span>
</span><span id="line-59"></span><span>      </span><span class="hs-identifier">startCB</span><span> </span><span class="hs-identifier">wh</span><span> </span><span class="hs-identifier">lpOverlapped</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-60"></span><span>        </span><span class="hs-identifier">ret</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">c_LockFileEx</span><span> </span><span class="hs-identifier">wh</span><span> </span><span class="hs-identifier">flags</span><span> </span><span class="hs-number">0</span><span> </span><span class="hs-number">4294967295</span><span> </span><span class="hs-number">4294967295</span><span>
</span><span id="line-61"></span><span class="hs-pragma">{-# LINE 61 &quot;libraries\\base\\GHC\\IO\\Handle\\Lock\\Windows.hsc&quot; #-}</span><span>
</span><span id="line-61"></span><span>                            </span><span class="hs-identifier">lpOverlapped</span><span>
</span><span id="line-62"></span><span>        </span><span class="hs-identifier">return</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">Mgr.CbNone</span><span> </span><span class="hs-identifier">ret</span><span>
</span><span id="line-63"></span><span>
</span><span id="line-64"></span><span>      </span><span class="hs-identifier">completionCB</span><span> </span><span class="hs-identifier">err</span><span> </span><span class="hs-identifier">_dwBytes</span><span>
</span><span id="line-65"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">err</span><span> </span><span class="hs-operator">==</span><span> </span><span class="hs-number">0</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Mgr.ioSuccess</span><span> </span><span class="hs-number">0</span><span>
</span><span id="line-66"></span><span class="hs-pragma">{-# LINE 66 &quot;libraries\\base\\GHC\\IO\\Handle\\Lock\\Windows.hsc&quot; #-}</span><span>
</span><span id="line-66"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">otherwise</span><span>                     </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Mgr.ioFailed</span><span> </span><span class="hs-identifier">err</span><span>
</span><span id="line-67"></span><span>
</span><span id="line-68"></span><span class="hs-identifier">lockImplPOSIX</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Handle</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">String</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">LockMode</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Bool</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">Bool</span><span>
</span><span id="line-69"></span><span class="hs-identifier">lockImplPOSIX</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-identifier">ctx</span><span> </span><span class="hs-identifier">mode</span><span> </span><span class="hs-identifier">block</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-70"></span><span>  </span><span class="hs-identifier">FD</span><span class="hs-special">{</span><span class="hs-identifier">fdFD</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">fd</span><span class="hs-special">}</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">handleToFd</span><span> </span><span class="hs-identifier">h</span><span>
</span><span id="line-71"></span><span>  </span><span class="hs-identifier">wh</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">throwErrnoIf</span><span> </span><span class="hs-special">(</span><span class="hs-operator">==</span><span> </span><span class="hs-identifier">iNVALID_HANDLE_VALUE</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">ctx</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">c_get_osfhandle</span><span> </span><span class="hs-identifier">fd</span><span>
</span><span id="line-72"></span><span>  </span><span class="hs-identifier">allocaBytes</span><span> </span><span class="hs-identifier">sizeof_OVERLAPPED</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">ovrlpd</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-73"></span><span>    </span><span class="hs-identifier">fillBytes</span><span> </span><span class="hs-identifier">ovrlpd</span><span> </span><span class="hs-number">0</span><span> </span><span class="hs-identifier">sizeof_OVERLAPPED</span><span>
</span><span id="line-74"></span><span>    </span><span class="hs-keyword">let</span><span> </span><span class="hs-identifier">flags</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">cmode</span><span> </span><span class="hs-operator">.|.</span><span> </span><span class="hs-special">(</span><span class="hs-keyword">if</span><span> </span><span class="hs-identifier">block</span><span> </span><span class="hs-keyword">then</span><span> </span><span class="hs-number">0</span><span> </span><span class="hs-keyword">else</span><span> </span><span class="hs-number">1</span><span class="hs-special">)</span><span>
</span><span id="line-75"></span><span class="hs-pragma">{-# LINE 75 &quot;libraries\\base\\GHC\\IO\\Handle\\Lock\\Windows.hsc&quot; #-}</span><span>
</span><span id="line-75"></span><span>    </span><span class="hs-comment">-- We want to lock the whole file without looking up its size to be</span><span>
</span><span id="line-76"></span><span>    </span><span class="hs-comment">-- consistent with what flock does. According to documentation of LockFileEx</span><span>
</span><span id="line-77"></span><span>    </span><span class="hs-comment">-- &quot;locking a region that goes beyond the current end-of-file position is</span><span>
</span><span id="line-78"></span><span>    </span><span class="hs-comment">-- not an error&quot;, hence we pass maximum value as the number of bytes to</span><span>
</span><span id="line-79"></span><span>    </span><span class="hs-comment">-- lock.</span><span>
</span><span id="line-80"></span><span>    </span><span class="hs-identifier">fix</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">retry</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">c_LockFileEx</span><span> </span><span class="hs-identifier">wh</span><span> </span><span class="hs-identifier">flags</span><span> </span><span class="hs-number">0</span><span> </span><span class="hs-number">4294967295</span><span> </span><span class="hs-number">4294967295</span><span>
</span><span id="line-81"></span><span class="hs-pragma">{-# LINE 81 &quot;libraries\\base\\GHC\\IO\\Handle\\Lock\\Windows.hsc&quot; #-}</span><span>
</span><span id="line-81"></span><span>                                 </span><span class="hs-identifier">ovrlpd</span><span> </span><span class="hs-operator">&gt;&gt;=</span><span> </span><span class="hs-glyph">\</span><span class="hs-glyph">case</span><span>
</span><span id="line-82"></span><span>      </span><span class="hs-identifier">True</span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-identifier">True</span><span>
</span><span id="line-83"></span><span>      </span><span class="hs-identifier">False</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">getLastError</span><span> </span><span class="hs-operator">&gt;&gt;=</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">err</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">if</span><span>
</span><span id="line-84"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">not</span><span> </span><span class="hs-identifier">block</span><span> </span><span class="hs-operator">&amp;&amp;</span><span> </span><span class="hs-identifier">err</span><span> </span><span class="hs-operator">==</span><span> </span><span class="hs-number">33</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-identifier">False</span><span>
</span><span id="line-85"></span><span class="hs-pragma">{-# LINE 85 &quot;libraries\\base\\GHC\\IO\\Handle\\Lock\\Windows.hsc&quot; #-}</span><span>
</span><span id="line-85"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">err</span><span> </span><span class="hs-operator">==</span><span> </span><span class="hs-number">995</span><span>           </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">retry</span><span>
</span><span id="line-86"></span><span class="hs-pragma">{-# LINE 86 &quot;libraries\\base\\GHC\\IO\\Handle\\Lock\\Windows.hsc&quot; #-}</span><span>
</span><span id="line-86"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">otherwise</span><span>                                         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">failWith</span><span> </span><span class="hs-identifier">ctx</span><span> </span><span class="hs-identifier">err</span><span>
</span><span id="line-87"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-88"></span><span>    </span><span class="hs-identifier">sizeof_OVERLAPPED</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="hs-number">32</span><span class="hs-special">)</span><span>
</span><span id="line-89"></span><span class="hs-pragma">{-# LINE 89 &quot;libraries\\base\\GHC\\IO\\Handle\\Lock\\Windows.hsc&quot; #-}</span><span>
</span><span id="line-89"></span><span>
</span><span id="line-90"></span><span>    </span><span class="hs-identifier">cmode</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="hs-identifier">mode</span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-91"></span><span>      </span><span class="hs-identifier">SharedLock</span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-number">0</span><span>
</span><span id="line-92"></span><span>      </span><span class="hs-identifier">ExclusiveLock</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-number">2</span><span>
</span><span id="line-93"></span><span class="hs-pragma">{-# LINE 93 &quot;libraries\\base\\GHC\\IO\\Handle\\Lock\\Windows.hsc&quot; #-}</span><span>
</span><span id="line-93"></span><span>
</span><span id="line-94"></span><span class="hs-identifier">unlockImpl</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Handle</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-95"></span><span class="hs-identifier">unlockImpl</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">unlockImplPOSIX</span><span> </span><span class="hs-operator">&lt;!&gt;</span><span> </span><span class="hs-identifier">unlockImplWinIO</span><span>
</span><span id="line-96"></span><span>
</span><span id="line-97"></span><span class="hs-identifier">unlockImplWinIO</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Handle</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-98"></span><span class="hs-identifier">unlockImplWinIO</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-99"></span><span>  </span><span class="hs-identifier">wh</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">handleToHANDLE</span><span> </span><span class="hs-identifier">h</span><span>
</span><span id="line-100"></span><span>  </span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">Mgr.withException</span><span> </span><span class="hs-string">&quot;unlockImpl&quot;</span><span> </span><span class="hs-operator">$</span><span>
</span><span id="line-101"></span><span>          </span><span class="hs-identifier">withOverlapped</span><span> </span><span class="hs-string">&quot;unlockImpl&quot;</span><span> </span><span class="hs-identifier">wh</span><span> </span><span class="hs-number">0</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">startCB</span><span> </span><span class="hs-identifier">wh</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">completionCB</span><span>
</span><span id="line-102"></span><span>  </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-103"></span><span>    </span><span class="hs-keyword">where</span><span>
</span><span id="line-104"></span><span>      </span><span class="hs-identifier">startCB</span><span> </span><span class="hs-identifier">wh</span><span> </span><span class="hs-identifier">lpOverlapped</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-105"></span><span>        </span><span class="hs-identifier">ret</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">c_UnlockFileEx</span><span> </span><span class="hs-identifier">wh</span><span> </span><span class="hs-number">0</span><span> </span><span class="hs-number">4294967295</span><span> </span><span class="hs-number">4294967295</span><span>
</span><span id="line-106"></span><span class="hs-pragma">{-# LINE 106 &quot;libraries\\base\\GHC\\IO\\Handle\\Lock\\Windows.hsc&quot; #-}</span><span>
</span><span id="line-106"></span><span>                              </span><span class="hs-identifier">lpOverlapped</span><span>
</span><span id="line-107"></span><span>        </span><span class="hs-identifier">return</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">Mgr.CbNone</span><span> </span><span class="hs-identifier">ret</span><span>
</span><span id="line-108"></span><span>
</span><span id="line-109"></span><span>      </span><span class="hs-identifier">completionCB</span><span> </span><span class="hs-identifier">err</span><span> </span><span class="hs-identifier">_dwBytes</span><span>
</span><span id="line-110"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">err</span><span> </span><span class="hs-operator">==</span><span> </span><span class="hs-number">0</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Mgr.ioSuccess</span><span> </span><span class="hs-number">0</span><span>
</span><span id="line-111"></span><span class="hs-pragma">{-# LINE 111 &quot;libraries\\base\\GHC\\IO\\Handle\\Lock\\Windows.hsc&quot; #-}</span><span>
</span><span id="line-111"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">otherwise</span><span>                     </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Mgr.ioFailed</span><span> </span><span class="hs-identifier">err</span><span>
</span><span id="line-112"></span><span>
</span><span id="line-113"></span><span class="hs-identifier">unlockImplPOSIX</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Handle</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-114"></span><span class="hs-identifier">unlockImplPOSIX</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-115"></span><span>  </span><span class="hs-identifier">FD</span><span class="hs-special">{</span><span class="hs-identifier">fdFD</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">fd</span><span class="hs-special">}</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">handleToFd</span><span> </span><span class="hs-identifier">h</span><span>
</span><span id="line-116"></span><span>  </span><span class="hs-identifier">wh</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">throwErrnoIf</span><span> </span><span class="hs-special">(</span><span class="hs-operator">==</span><span> </span><span class="hs-identifier">iNVALID_HANDLE_VALUE</span><span class="hs-special">)</span><span> </span><span class="hs-string">&quot;hUnlock&quot;</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">c_get_osfhandle</span><span> </span><span class="hs-identifier">fd</span><span>
</span><span id="line-117"></span><span>  </span><span class="hs-identifier">allocaBytes</span><span> </span><span class="hs-identifier">sizeof_OVERLAPPED</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">ovrlpd</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-118"></span><span>    </span><span class="hs-identifier">fillBytes</span><span> </span><span class="hs-identifier">ovrlpd</span><span> </span><span class="hs-number">0</span><span> </span><span class="hs-identifier">sizeof_OVERLAPPED</span><span>
</span><span id="line-119"></span><span>    </span><span class="hs-identifier">c_UnlockFileEx</span><span> </span><span class="hs-identifier">wh</span><span> </span><span class="hs-number">0</span><span> </span><span class="hs-number">4294967295</span><span> </span><span class="hs-number">4294967295</span><span> </span><span class="hs-identifier">ovrlpd</span><span> </span><span class="hs-operator">&gt;&gt;=</span><span> </span><span class="hs-glyph">\</span><span class="hs-glyph">case</span><span>
</span><span id="line-120"></span><span class="hs-pragma">{-# LINE 120 &quot;libraries\\base\\GHC\\IO\\Handle\\Lock\\Windows.hsc&quot; #-}</span><span>
</span><span id="line-120"></span><span>      </span><span class="hs-identifier">True</span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-121"></span><span>      </span><span class="hs-identifier">False</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">getLastError</span><span> </span><span class="hs-operator">&gt;&gt;=</span><span> </span><span class="hs-identifier">failWith</span><span> </span><span class="hs-string">&quot;hUnlock&quot;</span><span>
</span><span id="line-122"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-123"></span><span>    </span><span class="hs-identifier">sizeof_OVERLAPPED</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="hs-number">32</span><span class="hs-special">)</span><span>
</span><span id="line-124"></span><span class="hs-pragma">{-# LINE 124 &quot;libraries\\base\\GHC\\IO\\Handle\\Lock\\Windows.hsc&quot; #-}</span><span>
</span><span id="line-124"></span><span>
</span><span id="line-125"></span><span class="hs-comment">-- https://msdn.microsoft.com/en-us/library/aa297958.aspx</span><span>
</span><span id="line-126"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">ccall</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;_get_osfhandle&quot;</span><span>
</span><span id="line-127"></span><span>  </span><span class="hs-identifier">c_get_osfhandle</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">CInt</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">HANDLE</span><span>
</span><span id="line-128"></span><span>
</span><span id="line-129"></span><span class="hs-comment">-- https://msdn.microsoft.com/en-us/library/windows/desktop/aa365203.aspx</span><span>
</span><span id="line-130"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-keyword">interruptible</span><span> </span><span class="hs-string">&quot;LockFileEx&quot;</span><span>
</span><span id="line-131"></span><span>  </span><span class="hs-identifier">c_LockFileEx</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">DWORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">DWORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">DWORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">DWORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">LPOVERLAPPED</span><span>
</span><span id="line-132"></span><span>               </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">BOOL</span><span>
</span><span id="line-133"></span><span>
</span><span id="line-134"></span><span class="hs-comment">-- https://msdn.microsoft.com/en-us/library/windows/desktop/aa365716.aspx</span><span>
</span><span id="line-135"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-keyword">interruptible</span><span> </span><span class="hs-string">&quot;UnlockFileEx&quot;</span><span>
</span><span id="line-136"></span><span>  </span><span class="hs-identifier">c_UnlockFileEx</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">DWORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">DWORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">DWORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">LPOVERLAPPED</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">BOOL</span><span>
</span><span id="line-137"></span><span>
</span><span id="line-138"></span><span>
</span><span id="line-139"></span><span class="hs-pragma">{-# LINE 139 &quot;libraries\\base\\GHC\\IO\\Handle\\Lock\\Windows.hsc&quot; #-}</span><span>
</span><span id="line-139"></span></pre></body></html>